package com.itheima.comment.controller;

import com.itheima.comment.vo.CommentVo;
import com.itheima.comment.dto.CommentDto;
import com.itheima.comment.dto.CommentLikeDto;
import com.itheima.comment.dto.CommentSaveDto;
import com.itheima.comment.service.CommentService;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 发表评论
     * @return
     */
    @PostMapping("/save")
    public ResultVo save(@RequestBody CommentSaveDto dto){
        commentService.save(dto);
        return ResultVo.ok();
    }

    /**
     * 点赞评论或取消
     * @return
     */
    @PostMapping("/like")
    public ResultVo like(@RequestBody CommentLikeDto dto){
        commentService.like(dto);
        return ResultVo.ok();
    }

    /**
     * 获取文章的评论列表
     * @return
     */
    @PostMapping("/load")
    public ResultVo<List<CommentVo>> loadPage(@RequestBody CommentDto dto){
        List<CommentVo> voList = commentService.loadPage(dto);
        return ResultVo.ok(voList);
    }
}
